<?php
include_once "../header1.php";
?>
</head>
<body>
<?php
include_once ("../Login/databaseconnection.php");

$sessionSet=loggedin();
if(!isset($sessionSet))
{
require_once ("../index.php");
}
else
   {
if(!isset($_POST['Register']))
	{
	$maxid=mysql_query("SELECT max(Programme_Id) as maxId FROM programme");

while($rowid=mysql_fetch_array($maxid))
{
$m_Id=$rowid['maxId'];
$inum=substr("$m_Id",1);
$inn=($inum+1);
$Programme_Id='P';
if(strlen($inn)<strlen($inum))
{
for($i=0;$i<(strlen($inum)-strlen($inn));$i++)
{
$Programme_Id=$Programme_Id.'0';
}
$Programme_Id=$Programme_Id.$inn;
}
else
{
$Programme_Id=$Programme_Id.$inn;
}
}

	}
if(isset($_POST['Register']))
	   { 
	   $Programme_Id=$_POST['Pro_Id'];
	   if($Programme_Id!="")
	   {
$Sch_Che=mysql_query("SELECT * FROM programme WHERE Programme_Id='$Programme_Id'");
if($rows=mysql_fetch_array($Sch_Che))
		{
			$_SESSION['errorexi']="Sorry this Programme's record already exists";
		}
		else
		{
		if($_SESSION['Access_Type']=="Administrator")
   {
		require_once 'REGprog.php';
		}
		else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	}
}
}
	
?>
<?php

include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
<br/>
  <div id="lefttablereg">
  <form action="#" method="POST">
  <table width="512" height="111" border="0" class="tablefontv">
    <tr>
      <td height="21" colspan="8"  scope="row" class="err"><?php
		if(isset($_POST['Register']))
{
	if(isset($_SESSION['errorin']))
	{
		echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['error']))
	{
		echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['error'];
		unset($_SESSION['error']);
		
	}
	if(isset($_SESSION['errorexi']))
	{
		echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorexi'];
		unset($_SESSION['errorexi']);
		
	}
	
}
		?></td>
      </tr>
    <tr>
      <td width="64" scope="row">&nbsp;</td>
     
      <td width="12" height="21" scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td width="141" scope="row">  Programme Id:</td>
        <?php
	   if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Pro_Id' value='$Pro_Id'/>";
echo '</td>';

}
else
{
echo '<td>';
if(isset($Programme_Id))
{
echo "<input type='text' name='Pro_Id' value='$Programme_Id' readonly='readonly'/>";
}
else
{
echo "<input type='text' name='Pro_Id'/>";
}
echo '</td>';

}?>
      <th width="277" scope="row">&nbsp;</th>
    
     
	   
     
    </tr>
    <tr>
      <td scope="row">&nbsp;</td>
      <td height="21" scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td height="21" scope="row">Programme Name:</td>
        <?php
	   if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Pro_name' value='$Pro_name'/>";
echo '</td>';

}
else
{
echo '<td>';
echo "<input type='text' name='Pro_name'/>";
echo '</td>';

}?>
      <td height="21" scope="row" class="err"><?php
if(isset($_POST['Register']))
{
if(isset($_SESSION['errornotallo']))
{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errornotallo'];
unset($_SESSION['errornotallo']);
}
}
?></td>
    </tr>
    <tr>
      <th height="21" colspan="3" scope="row">&nbsp;</th>
      <th height="21" scope="row"></th>
    </tr>

  </table>
  <br/>
 <a href="RegProgrammes.php" class="reset">Reset |</a><input name="Register" align="middle" type="submit" value="Register" class="buttonok"/>
    </form>
    </div>
    <div id="righttablereg">
    <?php
		if(isset($_POST['Register']))
{
if(isset($_SESSION['OK']))
{
$result=mysql_query("SELECT * FROM programme");
echo '<br/>';
if(mysql_num_rows($result)!=0)
   {

echo '<table width="500" border="1" class="tablefontv" >
<tr bgcolor="#6AB5FF">
<td><font color="#000000">Programme Id</font></td>
<td><font color="#000000">Programme Name</font></td>
<td><font color="#000000">Last Updated Date</font></td></tr>';

  while($row=mysql_fetch_array($result))
  {
 $Prog_Id=$_SESSION['Pro_Id'];
if($row['Programme_Id']=="$Prog_Id")
  {
    echo '<tr bgcolor="#936">';
    echo '<td><font color="#000000">'.$row['Programme_Id'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Programme_Name'].'</font></td>';
	echo '<td><font color="#000000">'.$row['Last_Updated_Date'].'</font></td>';
    echo '</tr>';
  unset($_SESSION['Pro_Id']);
 }
 else
  {
    echo '<tr bgcolor="#CCCCCC">';
    echo '<td>'.$row['Programme_Id'].'</td>';
    echo '<td>'.$row['Programme_Name'].'</td>';
	echo '<td>'.$row['Last_Updated_Date'].'</td>';
  echo '</tr>';
  }
  }
   echo "</table>";

  }
  unset($_SESSION['OK']);
  }
  }
  
  ?>
    </div>
</div>
</div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">PROGRAMMES</h2>
            </div>
 <?php
include_once "menu.php";
?>
 <?php
include_once "../footer.php";
?>
<?php

	}
?>
</body>
</html>